<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>WebSocket Test</title>
</head>
<body>
<script>
    var socket = new WebSocket("ws://localhost:8080");

    // 连接成功时触发
    socket.onopen = function(event) {
        socket.send("Hello, Server!");
    };

    // 接收到消息时触发
    socket.onmessage = function(event) {
        console.log("Received data: " + event.data);
    };

    // 连接关闭时触发
    socket.onclose = function(event) {
        console.log("Connection closed.");
    };
</script>
</body>
</html>

